﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using SimpleCut.Data;

namespace SimpleCut.Control
{
    /// <summary>
    /// Interaction logic for SizeItemCtrol.xaml
    /// </summary>
    public partial class SizeItemCtrol : UserControl
    {
        public SizeItemCtrol()
        {
            InitializeComponent();
        }
        public SizeItemCtrol(SizeItemConfig config)
            : this()
        {
            DataContext = config;
            init();
        }
        private void init()
        {
            SizeItemConfig config = DataContext as SizeItemConfig;
            SizeItemNameTxtb.Text = config.Name;
            SizeItemResolutionTxtb.Text = "(" + config.Width.ToString() + "*" + config.Height.ToString() + ")";
            SizeItemRankTxt.Text = config.Rank.ToString();
        }
        public event Action<SizeItemConfig> RankChanged;
        public event Action<SizeItemConfig> SizeItemDeleted;
        private void SizeItemRankTxt_TextChanged(object sender, TextChangedEventArgs e)
        {
            SizeItemConfig config = DataContext as SizeItemConfig;
            config.Rank = Convert.ToInt32(
                SizeItemRankTxt.Text
                );
            if (RankChanged != null)
            {
                RankChanged(config);
            }
        }

        private void DeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            SizeItemConfig config = DataContext as SizeItemConfig;
            SizeItemDeleted(config);
        }
    }
}
